<template>
	<view>
		<u-search
			v-model="keyword"
			:show-action="false"
			@change="searchlist"
			placeholder="请输入关键字"
		></u-search>
		<u-list @scrolltolower="scrolltolower" v-if="buildworkerslist != false || status == 'loading'">
			<u-list-item v-for="(item, index) in buildworkerslist" :key="index">
				<u-cell :title="(index+1)+'、'+ item.Name" :label="'工号:' + item.WorkNo + ' 队长:' + item.WorkTeam + ' 劳务公司:' + item.WorkCompany" isLink @click="openpage" :name="item.Name">
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading" />
		</u-list>
		<u-empty mode="data" icon="https://project.gxrunxiang.com/cdn/list.png" v-else>
		</u-empty>
	</view>
</template>

<script>
	import {
		getworkerslist
	} from '@/common/api.js'
	export default {
		data() {
			return {
				buildworkerslist: [],
				keyword: "",
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true,
				user: {},
				keyword: "",
				userfilter:{}
			}
		},
		onLoad() {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.getlist()
		},
		methods: {
			openpage(e) {
				uni.redirectTo({
					url: "buildworkerinfo?name=" + e.name
				})
			},
			async getlist() {
				this.status = 'loading'
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters: [],
				}	
				if (this.keyword != "") {
					this.userfilter = {
						"ConditionalList": [{
							"Key": 0,
							"Value": {
								"FieldName": "Name",
								"FieldValue": this.keyword,
								"ConditionalType": "Like"
							}
						}, {
							"Key": 1,
							"Value": {
								"FieldName": "IdCardNo",
								"FieldValue": this.keyword,
								"ConditionalType": "Like"
							}
						}]
					}
					para.jsonPara=JSON.stringify( [this.userfilter])
				}
				if(this.user.Roles.indexOf('管理员角色')!=-1 || this.user.Roles.indexOf('项目经理角色')!=-1 || 
				   this.user.Roles.indexOf('劳务管理角色')!=-1|| this.user.Roles.indexOf('分管领导')!=-1 || 
				   this.user.Roles.indexOf('公司领导角色')!=-1 || this.user.Roles.indexOf('财务部经理')!=-1 ||
				   this.user.Roles.indexOf('部门领导角色')!=-1 || this.user.Roles.indexOf('部门内项目部审批人')!=-1){	   
				   }else{
					   para.Parameters.push({
					   	FieldName: "WorkTeam",
					   	ConditionalType: "Like",
					   	FieldValue: this.user.Name
					   })
				   }
				// para.Parameters.push({
				// 	FieldName: "Status",
				// 	ConditionalType: "Equal",
				// 	FieldValue: "已派工",
				// })
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				// if (querytype == "日志") {


				// }
				await getworkerslist(para).then(res => {
					let data = res.data
					this.buildworkerslist.push(...data)
					this.total = res.count
					this.totalPage = Math.ceil(this.total / this.pageSize)
				})
				if (this.buildworkerslist.length < this.pageSize) {
					this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
					this.status = 'nomore';
				}else {
					this.status = 'loadmore';
				}
			},
			scrolltolower() {
				// 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
				if (this.pageIndex >= this.totalPage) {
					this.status = 'nomore';
					return;
				};
				this.status = 'loading'; //状态改为加载中
				this.pageIndex = ++this.pageIndex; //页面新增一页
				this.getlist(); //修改页数后，重新获取数据
			},
			async searchlist() {
				this.buildworkerslist = [] //初始化
				this.pageIndex = 1 //初始化当前页数为1
				this.loading = true
				await this.getlist()
			}
			
		},
	}
</script>

<style>

</style>